Namespace My

    ' The following events are availble for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            If My.Settings.FirstRun = True Then
                frmStartup.ShowDialog()
                FavoritesFolder = My.Settings.BookmarkPath
            End If
            If My.Settings.CheckForUpdates = True Then
                CheckForUpdates("http://update.openbyte.info/OpenBookmarks.ini", True)
            End If
            Try
                AccessBookmarks.GetDirectoryStructure(FavoritesFolder)
                AddToRecentMenu(frmMain.RecentToolStripMenuItem)
            Catch ex As Exception
                frmMain.lblStatus.Text = "Error: " & Err.Description
            End Try
            frmMain.mnuMain.Location = My.Settings.MenuPosition
            frmMain.tlsBktoolbar.Location = My.Settings.ToolbarPosition
            frmMain.fsWatcher.Path = FavoritesFolder
            frmMain.icoTray.Visible = My.Settings.EnableTray
            frmMain.FindDeadBookmarksToolStripMenuItem.Visible = My.Settings.EnableExperimentalFeatures
        End Sub

        Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
            Select Case e.ExitApplication
                Case True
                    MessageBox.Show("The application has been forced to close due to an unexpected error.", My.Application.Info.ProductName & " (" & Err.Number & ")", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End
                Case False
                    ShowError(e.Exception.Message, e.Exception.ToString, Err.Number)
            End Select
        End Sub
    End Class

End Namespace